﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class PorductList : System.Web.UI.Page
{
    #region code
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        try
        {
            Convert.ToInt32(id);
        }
        catch
        {
            LIB.JsWrite.AlertAndGoback(this, "错误的参数");
        }
        litProduct1.Text = getProductList(id);
        litCataName.Text = getCataName(id);
    }

    private static string getCataName(string id)
    {
        string cataName = "寿山石";
        switch (id)
        {
            case "102": cataName = "昌化石"; break;
            case "103": cataName = "巴林石"; break;
            case "104": cataName = "鸡血石"; break;
            case "105": cataName = "杂石摆件"; break;
        }
        return cataName;
    }

    private string getProductList(string id)
    {
        BZZ.DataAcess worker = new BZZ.DataAcess();
        BZZ.CommonFunctions cf = new BZZ.CommonFunctions();
        #region 产品列表信息
        string sql = "select  * from product where professorID=" + id;
        DataSet dset = worker.Execute(sql);
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("            <table width=\"680\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
        //sb.Append("              <tr>");
        bool trBegin = false;
        int rowCount = dset.Tables[0].Rows.Count;
        #region get page para
        string p = Request.QueryString["p"];
        int CurrentPageNum = 1;
        try
        {
            CurrentPageNum = Convert.ToInt16(p);
        }
        catch { CurrentPageNum = 1; }
        if (CurrentPageNum == 0) CurrentPageNum++;
        int recordCount = dset.Tables[0].Rows.Count;
        int pageSize = 28;
        string para = "id=" + id;
        //Response.Write("p=" + CurrentPageNum.ToString() + ",count=" + recordCount.ToString());
        //Response.End();
        #endregion
        for (int i = (CurrentPageNum - 1) * pageSize; i < recordCount && i < CurrentPageNum * pageSize; i++)
        {
            #region 内容拼接
            DataRow row = dset.Tables[0].Rows[i];
            string varid = row["id"].ToString().Trim();
            string varPicURL = row["picURL"].ToString().Trim();//图片地址
            string varProductCode = row["productCode"].ToString().Trim();//作品编号
            string varProfessorID = row["professorID"].ToString().Trim();//作者姓名
            string varTitle = row["title"].ToString().Trim();//作品名称
            string varMaterial = row["material"].ToString().Trim();//作品材质
            string varSize = row["size"].ToString().Trim();//作品规格
            string varPrice = row["price"].ToString().Trim();//作品标价
            string varSale = row["sale"].ToString().Trim();//销售情况
            string varAbout = row["about"].ToString().Trim();//作品介绍
            string varMemo = row["memo"].ToString().Trim();//备注信息
            string varPubDate = row["pubDate"].ToString().Trim();//添加时间
            string varSortid = row["sortid"].ToString().Trim();//排序
            string varIsRecommend = row["isRecommend"].ToString().Trim();//是否推荐
            varPicURL = "img/" + varPicURL;
            if (i % 4 == 0)
            {
                sb.Append("<tr>");
                trBegin = true;
            }
            sb.Append("                <td width=\"148\" align=\"left\" valign=\"top\">");

            sb.Append("                <table width=\"148\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\">");
            sb.Append("                  <tr>");
            sb.Append("                    <td colspan=\"2\" align=\"center\" valign=\"top\"><table width=\"148\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\" bgcolor=\"#cfcfb8\">");
            sb.Append("                        <tr>");
            sb.Append("                          <td align=\"center\" valign=\"top\" bgcolor=\"#FFFFFF\"><a href=\"ProductDetail.aspx?id=" + varid + "\"><img src=\"" + varPicURL + "\" width=\"136\" height=\"104\" border=\"0\"></a></td>");
            //sb.Append("                          <td align=\"center\" valign=\"top\" bgcolor=\"#FFFFFF\"><a href=\"" + varPicURL.Replace("Thumb/", "") + "\" target=_blank><img src=\"" + varPicURL + "\" width=\"136\" height=\"104\" border=\"0\"></a></td>");
            sb.Append("                        </tr>");
            sb.Append("                    </table></td>");
            sb.Append("                    </tr>");
            //sb.Append("                  <tr>");
            //sb.Append("                    <td width=\"4\" align=\"center\" valign=\"top\" class=\"zt01\">&nbsp;</td>");
            //sb.Append("                    <td width=\"142\" align=\"left\" valign=\"top\" class=\"zt01\">编号：" + varProductCode + " </td>");
            //sb.Append("                  </tr>");
            //sb.Append("                  <tr>");
            //sb.Append("                    <td align=\"center\" valign=\"top\" class=\"zt01\">&nbsp;</td>");
            //sb.Append("                    <td align=\"left\" valign=\"top\" class=\"zt01\">品名：" + varTitle + "</td>");
            //sb.Append("                  </tr>");
            //sb.Append("                  <tr>");
            //sb.Append("                    <td align=\"center\" valign=\"top\" class=\"zt01\">&nbsp;</td>");
            //sb.Append("                    <td align=\"left\" valign=\"top\" class=\"zt01\">规格：" + varSize + "</td>");
            //sb.Append("                  </tr>");
            //sb.Append("                  <tr>");
            //sb.Append("                    <td align=\"center\" valign=\"top\" class=\"zt01\">&nbsp;</td>");
            //sb.Append("                    <td align=\"left\" valign=\"top\" class=\"zt01\">售价：" + varPrice + "</td>");
            //sb.Append("                  </tr>");
            //sb.Append("                  <tr>");
            //sb.Append("                    <td align=\"center\" valign=\"top\" class=\"zt01\">&nbsp;</td>");
            //sb.Append("                    <td align=\"left\" valign=\"top\" class=\"zt01\">状态：" + varSale + "</td>");
            //sb.Append("                  </tr>");
            sb.Append("                </table></td>");
            if (i % 4 == 3)
            {
                sb.Append("</tr>");
                trBegin = false;
            }
            #endregion

        }
        if (trBegin)
        {
            for (int t = 0; t < rowCount % 4; t++) sb.Append("<td width=\"148\">&nbsp;</td>");
            sb.Append("</tr>");
        }
        //sb.Append("              <tr>");
        //sb.Append("                <td colspan=\"4\" align=\"right\" valign=\"top\" class=\"zt01\">&nbsp;</td>");
        //sb.Append("              </tr>");
        //sb.Append("              <tr>");
        //sb.Append("                <td colspan=\"4\" align=\"right\" valign=\"top\" class=\"zt01\">共有4条 首页　上一页 下一页　尾页 页次:1/1页 12条/页</td>");
        //sb.Append("                </tr>");
        sb.Append("            </table>");
        sb.Append(cf.getPageHtml(CurrentPageNum, recordCount, pageSize, para));
        #endregion
        return sb.ToString();
    }



    #endregion

}
